package org.apache.beam.examples.Models;

import java.io.Serial;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.StringJoiner;


/**
 * 字典内容
 */
public class NounNode implements Serializable {

    @Serial
    private static final long serialVersionUID = 1L;
    /**
     * 字典编号
     */
    private String code;
    /**
     * 字典名称
     */
    private String name;
    /**
     * 字典说明
     */
    private String description;

    /**
     * 字典类型
     */
    private String type;
    /**
     * 字典属性
     */
    private String paramStr;

    /**
     * 父节点
     */
    private NounNode superNode;

    /**
     * 孩子节点
     */
    private List<NounNode> children;

    /**
     * 对象内容
     * @param code 编号
     * @param name 名称
     * @param description 说明
     * @param type 类型
     * @param paramStr 属性字段
     * @param superNode 上级节点
     * @param children 下级节点
     */
    public NounNode(String code, String name, String description, String type, String paramStr, NounNode superNode, List<NounNode> children) {
        this.code = code;
        this.name = name;
        this.description = description;
        this.type = type;
        this.paramStr = paramStr;
        this.superNode = superNode;
        this.children = children;
    }

    public NounNode(String code, String name, String description, String type, String paramStr) {
        this.code = code;
        this.name = name;
        this.description = description;
        this.type = type;
        this.paramStr = paramStr;
        this.children = new ArrayList<>();
    }

    public NounNode() {
        this.children = new ArrayList<>();
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public String getParamStr() {
        return paramStr;
    }

    public void setParamStr(String paramStr) {
        this.paramStr = paramStr;
    }

    public NounNode getSuperNode() {
        return superNode;
    }

    public void setSuperNode(NounNode superNode) {
        this.superNode = superNode;
    }

    public List<NounNode> getChildren() {
        return children;
    }

    public void setChildren(List<NounNode> children) {
        this.children = children;
    }

    public boolean childrenAdd(NounNode nounNode){
        nounNode.setSuperNode(this);
        if (children.contains(nounNode))return true;
        return children.add(nounNode);
    }
    public boolean childrenRemove(NounNode nounNode){
        return children.remove(nounNode);
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        NounNode nounNode = (NounNode) o;
        return Objects.equals(getCode(), nounNode.getCode()) && Objects.equals(getName(), nounNode.getName()) && Objects.equals(getDescription(), nounNode.getDescription()) && Objects.equals(getType(), nounNode.getType()) && Objects.equals(getParamStr(), nounNode.getParamStr()) && Objects.equals(getSuperNode(), nounNode.getSuperNode()) && Objects.equals(getChildren(), nounNode.getChildren());
    }

    @Override
    public int hashCode() {
        int result = Objects.hashCode(getCode());
        result = 31 * result + Objects.hashCode(getName());
        result = 31 * result + Objects.hashCode(getDescription());
        result = 31 * result + Objects.hashCode(getType());
        result = 31 * result + Objects.hashCode(getParamStr());
        result = 31 * result + Objects.hashCode(getSuperNode());
        result = 31 * result + Objects.hashCode(getChildren());
        return result;
    }

    @Override
    public String toString() {
        return new StringJoiner(", ", NounNode.class.getSimpleName() + "[", "]")
                .add("code='" + code + "'")
                .add("name='" + name + "'")
                .add("description='" + description + "'")
                .add("type='" + type + "'")
                .add("paramStr='" + paramStr + "'")
                .add("superNode=" + superNode)
                .add("children=" + children)
                .toString();
    }
}
